<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // 获取表单数据
    $amount = isset($_POST['selected_amount']) ? floatval($_POST['selected_amount']) : 0;
    $payment_method = isset($_POST['payment_method']) ? $_POST['payment_method'] : '';
    
    // 简单的数据验证
    if ($amount <= 0) {
        die("错误：请选择有效的打赏金额");
    }
    
    if (!in_array($payment_method, ['wechat', 'alipay'])) {
        die("错误：请选择有效的支付方式");
    }
    
    // 在实际应用中，这里应该连接到支付网关API
    // 以下只是模拟处理
    
    // 生成随机订单号
    $order_id = date('YmdHis') . rand(1000, 9999);
    
    // 记录打赏信息（在实际应用中，应该存入数据库）
    $donation_info = [
        'order_id' => $order_id,
        'amount' => $amount,
        'payment_method' => $payment_method,
        'time' => date('Y-m-d H:i:s')
    ];
    
    // 显示成功页面
    echo "<!DOCTYPE html>
    <html lang='zh-CN'>
    <head>
        <meta charset='UTF-8'>
        <title>打赏成功</title>
        <style>
            body { 
                font-family: Arial, sans-serif; 
                text-align: center; 
                padding: 50px; 
                background: #f5f7fa;
            }
            .success-card {
                background: white;
                padding: 40px;
                border-radius: 16px;
                box-shadow: 0 10px 30px rgba(0,0,0,0.1);
                display: inline-block;
                max-width: 500px;
            }
            h1 { color: #4caf50; }
            .info { 
                text-align: left; 
                background: #f9f9f9;
                padding: 20px;
                border-radius: 8px;
                margin: 20px 0;
            }
            .back-btn {
                background: #667eea;
                color: white;
                padding: 12px 24px;
                border: none;
                border-radius: 8px;
                cursor: pointer;
                font-size: 16px;
                margin-top: 20px;
            }
        </style>
    </head>
    <body>
        <div class='success-card'>
            <h1>打赏成功！</h1>
            <p>感谢您的支持，您的打赏将帮助我们持续创造优质内容。</p>
            
            <div class='info'>
                <p><strong>订单号：</strong> {$donation_info['order_id']}</p>
                <p><strong>打赏金额：</strong> ￥{$donation_info['amount']}</p>
                <p><strong>支付方式：</strong> " . ($donation_info['payment_method'] == 'wechat' ? '微信支付' : '支付宝') . "</p>
                <p><strong>支付时间：</strong> {$donation_info['time']}</p>
            </div>
            
            <button class='back-btn' onclick='window.history.back()'>返回</button>
        </div>
    </body>
    </html>";
} else {
    // 如果不是POST请求，重定向到打赏页面
    header('Location: index.html');
    exit;
}
?>